package cn.houserent.web;

import cn.houserent.pojo.Users;
import cn.houserent.service.UserBiz;
import org.springframework.stereotype.Service;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = {"/ActionServlet"}, name = "ActionServlet")
public class ActionServlet extends javax.servlet.http.HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String name = request.getParameter("name");
        String password = request.getParameter("password");

        List<Users> list = new UserBiz().loginUser(name,password);

        if (list != null || list.size() > 0) {
            request.setAttribute("user",list.get(0).getName());
            request.getRequestDispatcher("list.jsp").forward(request,response);
        } else {
            request.setAttribute("meg","登录失败！");
        }
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
